home *** CD-ROM | disk | FTP | other *** search
/ Leonardo the Inventor / Leonardo The Inventor (93026)(Broderbund)(Riverdeep)(2004).iso / LEOWINMV / DATABASE.DIR / 00103_Script_INDEX INDEX < prev    next >
Text File  |  1996-03-28  |  5KB  |  134 lines

  1. -- --------------------------------------------------------------
  2. -- Handler setLeo2Index 
  3.  
  4. on setLeo2Index
  5.   extractIndexIndex 332, 357
  6.   spreadIndexIndexToCasts 358, 360
  7. end
  8.  
  9. -- --------------------------------------------------------------
  10. -- Handler extractIndexIndex is given the numbers of the first
  11. -- index cast and the last index cast and creates an index of the
  12. -- index where entries of the indexIndex are of the form:
  13. -- <indexEntry>:<indexCast>:<line in indexCast>
  14.  
  15. on extractIndexIndex firstCast, lastCast
  16.   global IndexIndex
  17.   
  18.   set IndexIndex = ""
  19.   
  20.   repeat with C = firstCast to lastCast
  21.     put "Extracting cast: " & the name of cast C -- LOG
  22.     set indexText = field C
  23.     
  24.     repeat with L = 1 to the number of lines of indexText - 1
  25.       set aLine = line L of indexText
  26.       if (char 1 of aLine = "*") then
  27.         put (char 2 to 99 of aLine) & ":" & C & ":" & L & RETURN after IndexIndex 
  28.       end if
  29.     end repeat
  30.   end repeat
  31.   
  32.   put "Finished Extracting." -- LOG
  33. end
  34.  
  35. -- --------------------------------------------------------------
  36. -- Handler spreadIndexIndexToCasts divides the global variable
  37. -- indexIndex (created in extractIndexIndex) into groups of
  38. -- 1000 lines and stores these lines in cast members named
  39. -- "IndexIndex1", "IndexIndex2" ...
  40.  
  41. on spreadIndexIndexToCasts firstCast, lastCast
  42.   global indexIndex
  43.   
  44.   set numLines = the number of lines of IndexIndex
  45.   
  46.   repeat with C = 1 to (lastCast + 1) - firstCast
  47.     put line ((C - 1) * 1000 ) + 1 to ((C - 1) * 1000 ) + 1000 of indexIndex into cast firstCast + C - 1
  48.     put RETURN after cast firstCast + C - 1
  49.     set the name of cast firstCast + C - 1 to "IndexIndex " & string(C)
  50.   end repeat
  51.   put "Finished Spreading.  Casts: " & firstCast && "to" && lastCast -- LOG
  52. end
  53.  
  54. -- --------------------------------------------------------------
  55. -- Handler initIndexIndex initialized four global variables,
  56. -- indexIndex1, ... indexIndex4 to the index of the index (stored
  57. -- in fields "IndexIndex1", "IndexIndex2" ... "IndexIndex<n>").
  58.  
  59. on initIndexIndex 
  60.   global IndexIndex1, IndexIndex2, IndexIndex3, IndexIndex4
  61.   
  62.   set indexIndex1 = ""
  63.   set indexIndex2 = ""
  64.   set indexIndex3 = ""
  65.   set indexIndex4 = ""
  66.   
  67.   repeat with C = 1 to 3
  68.     set pack = (the text of field ("indexIndex" && string(C))) & RETURN
  69.     set IndexIndex1 = IndexIndex1 & pack
  70.     set pack = ""
  71.   end repeat
  72.   
  73.   --  repeat with C = 4 to 6
  74.   --    set pack = (the text of field ("indexIndex" && string(C))) & RETURN
  75.   --    set IndexIndex2 = IndexIndex2 & pack
  76.   --    set pack = ""
  77.   --  end repeat
  78.   --  
  79.   --  repeat with C = 7 to 9
  80.   --    set pack = (the text of field ("indexIndex" && string(C))) & RETURN
  81.   --    set IndexIndex3 = IndexIndex3 & pack
  82.   --    set pack = ""
  83.   --  end repeat
  84.   --  
  85.   --  repeat with C = 10 to 13
  86.   --    set pack = (the text of field ("indexIndex" && string(C))) & RETURN
  87.   --    set IndexIndex4 = IndexIndex4 & pack
  88.   --    set pack = ""
  89.   --  end repeat
  90. end
  91.  
  92.  
  93. -- --------------------------------------------------------------
  94. -- Handler getIndexIndexData returns the index of the given word
  95. -- using the index of the index.
  96.  
  97. on getIndexIndexData aWord
  98.   global IndexIndex1, IndexIndex2, IndexIndex3, IndexIndex4
  99.   
  100.   set the itemDelimiter = ":"
  101.   
  102.   -- quick search, get the indexIndex that contains the given
  103.   -- word by comparing it to the first word in the indices.
  104.   --  if (aWord < item 1 of IndexIndex2) then
  105.   --    set theIndexIndex = IndexIndex1
  106.   --  else if (aWord < item 1 of IndexIndex3) then
  107.   --    set theIndexIndex = IndexIndex2
  108.   --  else if (aWord < item 1 of IndexIndex4) then
  109.   --    set theIndexIndex = IndexIndex3
  110.   --  else
  111.   --    set theIndexIndex = IndexIndex4
  112.   --  end if
  113.   
  114.   set theIndexIndex = IndexIndex1
  115.   
  116.   -- now get the line in the indexIndex that contains the word
  117.   set theLine = binSearchFirstItemInLine (theIndexIndex, aWord, ":")
  118.   
  119.   if (theLine = 0) then -- the word is not in the index
  120.     set the itemDelimiter = ","
  121.     return ""
  122.   end if
  123.   
  124.   -- the word is in the index
  125.   set wordData = line theLine of theIndexIndex
  126.   set nextWordData = line theLine + 1 of theIndexIndex
  127.   set indexCast = item 2 of wordData
  128.   set indexCastLine1 = item 3 of wordData
  129.   set indexCastLine2 = item 3 of nextWordData
  130.   
  131.   set the itemDelimiter = ","
  132.   
  133.   return line value(indexCastLine1)+1 to value(indexCastLine2)-1 of field value(indexCast)
  134. end